*WHAT'S ACROSS THE BORDER?
*JHA, NEUMARK, AND RODRIGUEZ-LOPEZ

include directories.do

*********** CONTIGUOUS PAIR SPECIFICATIONS FOR (5) AND (6) OF DLR'S TABLE 2 *****
*********** FOR BOTH COUNTY-PAIRS AND MULTI-STATE CZONES ************************
*********** EXTRACT FROM DLR'S "MAIN ANALYSIS 11-6-09.DO" ***********************


foreach d in "co" "cz" {

use "`dlrdir'`s'QCEWindustry_minwage_contig_`d'.dta", clear

**

*TO CORRECT DRL'S STANDARD ERRORS IN COUNTY-PAIR REGRESSIONS (PAIRTIMES==2)
merge m:1 pair_id using "`dlrdir'`s'`d'_pairs_dlr.dta"

drop if _merge==2
drop _merge

*keep if pairtimes==2 
**

egen pair_id_num = group(pair_id)
gen sample_5 = 1
gen absorb_5 = period
gen sample_6 = 1
egen absorb_6 = group(pair_id period)

sort  pair_id period
 
gen state_a = real(substr(pair_id, 1,2))
gen state_b = real(substr(pair_id, 7,2))

gen st_min = min( state_a, state_b)
gen st_max = max(state_a, state_b)
egen bordersegment = group(st_min st_max)

xi: areg lnMW   ,  absorb(county)
predict lnMWR , res

xi: areg lnpop   ,    absorb(county)
predict lnpopR, res 

xi: areg lnemp_TOT   ,    absorb(county)
predict lnemp_TOTR, res 

xi: areg lnAWW_TOT   ,   absorb(county)
predict lnAWW_TOTR, res

*K loops through industries .

foreach k in rest_both  {

xi: areg lnAWW_`k', absorb(county)
predict lnAWW_`k'R, res 
 
xi: areg lnemp_`k'   , absorb(county)
predict lnemp_`k'R, res


forval specification = 5/5 {

eststo m1_emp_`specification'_`d': cluster2areg lnemp_`k'R lnMWR lnpopR if sample_`specification'==1 & nonmissing_`k'==66, fcluster(state_fips) w(all) tcluster(bordersegment) a(absorb_`specification')

eststo m2_emp_`specification'_`d': cluster2areg lnemp_`k'R lnMWR lnemp_TOTR lnpopR if sample_`specification'==1 & nonmissing_`k'==66, fcluster(state_fips) w(all) tcluster(bordersegment) a(absorb_`specification')

eststo m1_AWW_`specification'_`d': cluster2areg lnAWW_`k'R lnMWR  if sample_`specification'==1 & nonmissing_`k'==66,  fcluster(state_fips) w(all) tcluster(bordersegment) a(absorb_`specification')

eststo m2_AWW_`specification'_`d': cluster2areg lnAWW_`k'R lnAWW_TOTR lnMWR  if sample_`specification'==1 & nonmissing_`k'==66,  fcluster(state_fips) w(all) tcluster(bordersegment) a(absorb_`specification')

}

forval specification = 6/6 {

eststo m1_emp_`specification'_`d': cluster2areg lnemp_`k'R lnMWR lnpopR if sample_`specification'==1 & pairtimes==2 & nonmissing_`k'==66, fcluster(state_fips) w(all) tcluster(bordersegment) a(absorb_`specification')
 
eststo m2_emp_`specification'_`d': cluster2areg lnemp_`k'R lnMWR lnemp_TOTR lnpopR if sample_`specification'==1 & pairtimes==2 & nonmissing_`k'==66, fcluster(state_fips) w(all) tcluster(bordersegment) a(absorb_`specification')

eststo m1_AWW_`specification'_`d': cluster2areg lnAWW_`k'R lnMWR  if sample_`specification'==1 & pairtimes==2 & nonmissing_`k'==66,  fcluster(state_fips) w(all) tcluster(bordersegment) a(absorb_`specification')
 
eststo m2_AWW_`specification'_`d': cluster2areg lnAWW_`k'R lnAWW_TOTR lnMWR  if sample_`specification'==1 & pairtimes==2 & nonmissing_`k'==66,  fcluster(state_fips) w(all) tcluster(bordersegment) a(absorb_`specification')
 

}


}
}
/* Print results */


tempfile specs


#delimit ;
esttab m1_emp_5_co m2_emp_5_co m1_emp_6_co m2_emp_6_co using "`specs'.csv", ///
    nodepvars ///
    collabels(, none) ///
    mlabels(, none) ///
    b(%9.3f) se(%9.3f) ///
    star(* .10 ** .05 *** .01) ///
    title("CBCP-employment") ///
	keep(lnMWR)
    nonotes ///
    label ///
    stats(N, labels("N") fmt(0))
    replace;
#delimit cr

#delimit ;
esttab m1_AWW_5_co m2_AWW_5_co m1_AWW_6_co m2_AWW_6_co using "`specs'.csv", ///
    nodepvars ///
    collabels(, none) ///
    mlabels(, none) ///
    b(%9.3f) se(%9.3f) ///
    star(* .10 ** .05 *** .01) ///
    title("CBCP-earnings") ///
	keep(lnMWR)
    nonotes ///
    label ///
	stats(N, labels("N") fmt(0))
    append;
#delimit cr

#delimit ;
esttab m1_emp_5_cz m2_emp_5_cz m1_emp_6_cz m2_emp_6_cz  using "`specs'.csv", ///
    nodepvars ///
    collabels(, none) ///
    mlabels(, none) ///
    b(%9.3f) se(%9.3f) ///
    star(* .10 ** .05 *** .01) ///
    title("MSCZP-employment") ///
	keep(lnMWR)
    nonotes ///
    label ///
	stats(N, labels("N") fmt(0))
    append;
#delimit cr

#delimit ;
esttab m1_AWW_5_cz m2_AWW_5_cz m1_AWW_6_cz m2_AWW_6_cz using "`specs'.csv", ///
    nodepvars ///
    collabels(, none) ///
    mlabels(, none) ///
    b(%9.3f) se(%9.3f) ///
    star(* .10 ** .05 *** .01) ///
    title("MSCZP-earnings") ///
	keep(lnMWR)
    nonotes ///
    label ///
	stats(N, labels("N") fmt(0))
    append;
#delimit cr

insheet using "`specs'.csv", comma clear
export excel "`outdir'`s'TablesJNR.xlsx", sheetreplace sheet(Table1)


clear all
